/**
 * Created by Administrator on 2016/11/8.
 */
var exit = document.querySelector(".exit");
var login = document.querySelector(".login");
var login_div = document.querySelector(".login_div");
var my_top = document.querySelector(".top");
var move_span = document.getElementById('move');
var rb_change = document.querySelector(".change");
var b_change = document.querySelector(".bottom_div");
var r_change = document.querySelector(".right_div");
var flag,flag1;
var login_top,login_left,login_width,login_height;
//点击关闭符号和透明层，透明层和登陆界面消失
function Delete(){
    login.style.display = "none";
    login_div.style.display = "none";
}
exit.onclick = Delete;
login_div.onclick = Delete;
//点击绿色头部，透明层和登陆界面出现
my_top.onclick = function(){
    login.style.display = "block";
    login_div.style.display = "block";
};
//登陆界面在中间
function positionCenter(){
    var window_width = document.documentElement.clientWidth;
    var window_height = document.documentElement.clientHeight;
    var login_width = login.offsetWidth;
    var login_height = login.offsetHeight;
    login.style.top = (window_height-login_height)/2 + 'px';
    login.style.left = (window_width-login_width)/2 + 'px';
}
positionCenter();
//登陆界面随滚轴而动
function moveScroll(){
    var distance = document.body.scrollTop;
    var window_width = document.documentElement.clientWidth;
    var window_height = document.documentElement.clientHeight;
    var login_width = login.offsetWidth;
//    var login_height = login.offsetHeight;
    login.style.top = (window_height-login_height)/2+distance + 'px';
    login.style.left = (window_width-login_width)/2 + 'px';
}
window.onscroll = moveScroll;
//实现登陆界面的拖拽放大缩小
function move(ele){
    var element = ele;
     login_top = login.offsetTop;
     login_left = login.offsetLeft;
    flag = false;
    var window_width = document.documentElement.clientWidth;
    var window_height = document.documentElement.clientHeight;
    login_width = login.offsetWidth;
    login_height = login.offsetHeight;


    move_span.onmousedown = function(e){
        flag = true;
        var x = e.pageX;
        var y = e.pageY;
        document.onmousemove = function(e){
            if(flag){
                var max_x = (window_width - login_width);
                var max_y = (window_height - login_height);
                var move_x = e.pageX;
                var move_y = e.pageY;
                var dis_x = move_x-x;
                var dis_y = move_y-y;
                var moveX = Math.min(max_x,Math.max(0,login_left+dis_x));
                var moveY = Math.min(max_y,Math.max(0,login_top+dis_y));
                login.style.top = moveY + 'px';
                login.style.left = moveX + 'px';
            }else{
            }
        }
    };
    move_span.onmouseup = function(){
        flag = false;
        move(ele);
    }

    element.onmousedown = function(e){
//        alert('d')
//        alert(login_width);
//        alert(login_top)
        flag1 = true;
        var x = e.pageX;
        var y = e.pageY;
        document.onmousemove = function(e){
            if(flag1){
                var max_w = (window_width - login_left);
                var max_h = (window_height - login_top);
                var move_x = e.pageX;
                var move_y = e.pageY;
                var dis_x = move_x-x;
                var dis_y = move_y-y;
//                alert(login_height);
                var moveX = Math.min(max_w-8,Math.max(300,login_width+dis_x));
                var moveY = Math.min(max_h-10,Math.max(200,login_height+dis_y));
                switch(element){
                    case r_change:
                        login.style.width = moveX + 'px';
//                        login.style.left = moveX + 'px';
                        break;
                    case b_change:
                        login.style.height = moveY + 'px';
                        break;
                    case rb_change:
                        login.style.height = moveY + 'px';
                        login.style.width = moveX + 'px';
                        break;
                }
            }else{
//                alert('d')
            }
        }
    }
    document.onmouseup = function(){
//
        flag1 = false;
//        alert(flag1);
        move(ele);
    }
}
move(r_change);
move(b_change);
move(rb_change);
//拖拽边框变大变小
